package com.ch3cooh.common.resp;

import com.ch3cooh.common.constant.GlobalConstants;
import lombok.Data;

/**
 * Created by JackWangon[www.coder520.com] 2018/1/9.
 */
@Data
public class ApiResult<T> {

    private int code = GlobalConstants.RESP_STATUS_OK;

    private String message;

    private T data;

    public ApiResult() {
    }

    public ApiResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T>ApiResult success(String msg , T data){
        return new ApiResult<>(GlobalConstants.RESP_STATUS_OK ,msg,data);
    }

    public static <Void>ApiResult success(){
        return new ApiResult<>(GlobalConstants.RESP_STATUS_OK , "success");
    }

    public static <Void>ApiResult success(String msg){
        return new ApiResult<>(GlobalConstants.RESP_STATUS_OK , msg , null);
    }

    public static <T>ApiResult code400(String msg ){
        return new ApiResult<>(GlobalConstants.RESP_STATUS_BADREQUEST , msg);
    }



    public static <T>ApiResult error(String msg){
        return new ApiResult<>(GlobalConstants.RESP_STATUS_INTERNAL_ERROR , msg);
    }
}
